//
//  MyReplyHeader.m
//  心水宝典
//
//  Created by zr on 2018/8/31.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "MyReplyHeader.h"

@interface MyReplyHeader ()

@property (nonatomic, weak)UIImageView * backImageView;
@property (nonatomic, weak)UIImageView * iconImageView;
@property (nonatomic, weak)UILabel * nameLabel;
@property (nonatomic, weak)UILabel * personLabel;
@property (nonatomic, strong)UIButton * oneButton;
@property (nonatomic, strong)UIButton * twoButton;
@property (nonatomic, strong)UIView * oneLineView;
@property (nonatomic, strong)UIView * twoLineView;

@end

@implementation MyReplyHeader


- (void)setUrl:(NSURL *)url{
    
    _url = url;
    
    [self.iconImageView sd_setImageWithURL:url placeholderImage:ImageNamed(@"23sdasas")];
}


- (void)setName:(NSString *)name{
    
    _name = name;
    
    self.nameLabel.text = name;
}

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.userInteractionEnabled = YES;
    
    UIImageView * backImageView = [UIImageView new];
    
    backImageView.image = ImageNamed(@"bjsss");
    
    self.backImageView = backImageView;
    
    [self addSubview:self.backImageView];
    
    
    UIImageView * iconImageView = [UIImageView new];
    
    iconImageView.image = ImageNamed(@"23sdasas");
    iconImageView.layer.cornerRadius = 35 * SCREENH6;
    iconImageView.layer.masksToBounds = YES;
    
    self.iconImageView = iconImageView;
    
    [self addSubview:self.iconImageView];

    
    
    UILabel * nameLabel = [UILabel new];
    
    nameLabel.textColor = WHITE_COLOR;
    nameLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    nameLabel.text = @"神奇测试";
    
    self.nameLabel = nameLabel;
    
    [self addSubview:self.nameLabel];
    
    
    UILabel * personLabel = [UILabel new];
    
    personLabel.textColor = WHITE_COLOR;
    personLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    personLabel.text = @"这个人很懒暂时没写什么...";
    
    self.personLabel = personLabel;
    
    [self addSubview:self.personLabel];
    
    
    self.oneButton = [self setupButtonWith:@"我的回复"];
    self.oneButton.selected = YES;
    
    [self addSubview:self.oneButton];
    
    self.twoButton = [self setupButtonWith:@"我的点赞"];
    [self addSubview:self.twoButton];
    
    self.oneLineView = [self setupLineView];
    self.oneLineView.hidden = NO;
    
    [self addSubview:self.oneLineView];
    
    self.twoLineView = [self setupLineView];
    [self addSubview:self.twoLineView];

}



- (void)layoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.mas_equalTo(self);
        make.height.mas_equalTo(175 * SCREENH6);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self).offset(40 * SCREENH6);
        make.width.height.mas_equalTo(70 * SCREENH6);
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.personLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.top.mas_equalTo(self.nameLabel.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.oneButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.bottom.mas_equalTo(self);
        make.top.mas_equalTo(self.backImageView.mas_bottom).offset(5 * SCREENH6);
        make.width.mas_equalTo(SCREEN_WIDTH / 2);
    }];
    
    [self.twoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.width.height.mas_equalTo(self.oneButton);
        make.leading.mas_equalTo(self.oneButton.mas_trailing);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self);
        make.height.mas_equalTo(5 * SCREENH6);
        make.width.mas_equalTo(73 * SCREENH6);
        make.centerX.mas_equalTo(self.oneButton);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.height.width.mas_equalTo(self.oneLineView);
        make.centerX.mas_equalTo(self.twoButton);
    }];
}



- (UIButton *)setupButtonWith:(NSString *)string{
    
    UIButton * button = [UIButton new];
    
    [button setTitle:string forState:UIControlStateNormal];
    [button setTitleColor:ColorWithRGB(0x585858) forState:UIControlStateNormal];
    [button setTitleColor:ColorWithRGB(0xF52F4C) forState:UIControlStateSelected];
    button.titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}


- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xF52F4C);
    lineView.hidden = YES;
    
    return lineView;
}


- (void)clickButton:(UIButton *)button{
    
    NSString * type;
    
    if (button == self.oneButton) {
        
        if (!self.oneButton.selected) {
            
            self.oneLineView.hidden = NO;
            self.oneButton.selected = YES;
            
            self.twoButton.selected = NO;
            self.twoLineView.hidden = YES;
            
            type = @"one";
        }
    }else if (button == self.twoButton){
        
        if (!self.twoButton.selected) {
            
            self.twoLineView.hidden = NO;
            self.twoButton.selected = YES;
            
            self.oneButton.selected = NO;
            self.oneLineView.hidden = YES;
            type = @"two";
        }
    }
    
    NSDictionary * dict = @{@"type":type};
    
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ChangeMyReplyOrLikeData" object:nil userInfo:dict];
}


@end
